#include "mainwindow.h"
#include "PostedEvent.h"
#include "SendEvent.h"
#include "progressbar.h"
#include "ui_mainwindow.h"
#include <QPushButton>
#include <QApplication>


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    init();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::init()
{
    connect(ui->pbt_showBar,&QPushButton::clicked,this,&MainWindow::onShowBar);
}

void userPostEvent()
{
    Worker* worker = new Worker();
    worker->receiverObj = new Receiver();

    worker->start();
}

void userSendEvent()
{
    SendEvent* eventer = new SendEvent();
    eventer->receiverObj = new SendReceiver();
    eventer->userSendEvent();
}

void MainWindow::test()
{
    userSendEvent();
}

void MainWindow::onShowBar()
{
    ProgressBar* bar = new ProgressBar();
    bar->setMaxValue(100);
    bar->show();
    for(int i = 1;i <= 100;i++)
    {
        bar->setProgessBarCurValue(i);
        QThread::msleep(20);
        // 事件派发，刷新及时更新进度条
        QApplication::processEvents();
    }
    bar->closeWindow();
}

